home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr35
/
dwnsrs57.zip
/
DOWNRPT3.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-22
|
23KB
|
458 lines
/* =============================================================== */
/* Rob Hamerling's MAXIMUS download file scan and sort utility */
/* -> DOWNRPT3.C */
/* -> Make SYSOP lists: ORP-list, DUP-list, OK-file, all FILES.BBS */
/* ================================================================ */
#define INCL_BASE
#define INCL_NOPMAPI
#include <os2.h>
#include <conio.h>
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "..\max\mstruct.h"
#include "downsort.h"
#include "downfpro.h"
/* prototypes of local functions */
int filename_cmp(FILECHAIN **, unsigned int);
int dup_ext(FILECHAIN **, unsigned int, unsigned int);
/* ------------------------- */
/* Produce the ORPHAN report */
/* ------------------------- */
void make_orp(FILECHAIN **dm,
DOWNPATH _HUGE *area,
unsigned int x) /* report privilege index */
{
FILE *pf; /* file handle */
char outfile[MAXFN]; /* file names */
unsigned int i,j,fc; /* counters */
sprintf(outfile,"%s.%s",lp[P_ORP].name,lp[P_ORP].ext); /* build fname */
if (oper_mode==VERBOSE)
fprintf(stdout, MSG_SRT, file_total_count, area_total_count, outfile);
switch(lp[P_ORP].sortflag) { /* sort */
case ALPHA: psort(dm,0,file_total_count-1,sort_gbl); break;
case TIMESTAMP: psort(dm,0,file_total_count-1,sort_new); break;
default: break;
}
fc = preproc_area(area, dm, lp[P_ORP].priv[x]); /* files within priv */
j = file_total_count - fc; /* calc orphans */
if (j>0) { /* yes, there are orphans */
pf = fopen(outfile,WRITE); /* output file */
if (pf != NULL) { /* successful open */
if (oper_mode != QUIET)
fprintf(stdout, MSG_REP, outfile);
if (oper_mode == VERBOSE)
fprintf(stdout, MSG_REC);
block_title(pf, 9, " Orphans ", P_ORP); /* generate block title */
fprintf(pf, "\n");
sep_line(pf, '═', 79, 0);
fprintf(pf," %s %s %s %-s\n", AC, FN, DT, FP);
sep_line(pf, '─', 8, 12, 9, 47, 0);
for (i=j=0; i<file_total_count; i++) {
if (dm[i]->priv >= HIDDEN) { /* report "hidden" and up */
if (oper_mode==VERBOSE && (j%25)==0) {
fprintf(stdout, " %5u\r", j);
fflush(stdout);
}
++j; /* list file-count */
dm[i]->fdesc = ORPHAN; /* assign 'description' */
fprintf(pf,"%8.8s %-12.12s %s%c ",
dm[i]->parea->name,
dm[i]->fname,
f_date(dm[i]->wdate),
file_age_ind(dm[i]->cdate,dm[i]->ctime)); /*age*/
desc_part(pf,
(dm[i]->fpath==NULL) ? dm[i]->parea->pname :
dm[i]->fpath,
47, 47, P_ORP);
}
}
if (oper_mode==VERBOSE) {
fprintf(stdout, " %5u\n",j); /* total reported orphans */
fflush(stdout);
}
signature(pf,today); /* fingerprint */
fclose(pf); /* finished with .ORP file */
}
else /* no output possible */
fprintf(stderr, MSG_OPO, outfile, 0);
}
}
/* ------------------ */
/* Produce a DUP-list */
/* ------------------ */
void make_dup(FILECHAIN **dm,
unsigned int x) /* list privilege index */
{
FILE *pf; /* file handle */
char outfile[MAXFN]; /* file names */
unsigned int i,j; /* counters */
sprintf(outfile,"%s.%s", lp[P_DUP].name, lp[P_DUP].ext);
pf = fopen(outfile,WRITE); /* output file */
if (pf != NULL) {
if (oper_mode == VERBOSE)
fprintf(stdout, MSG_SRT, file_total_count, area_total_count, outfile);
psort(dm, 0, file_total_count-1, sort_gbl); /* filename sort */
if (oper_mode != QUIET)
fprintf(stdout, MSG_REP, outfile);
if (oper_mode == VERBOSE)
fprintf(stdout, MSG_REC);
block_title(pf, 12, " Duplicates ", P_DUP);
if (lp[P_DUP].exclflag != EXCLPRIV)
fprintf(pf,"\n%s%s\n",
MP, priv_name[lp[P_DUP].priv[x]-TWIT]);
fprintf(pf,"\n%s %s %s %s %s\n",FN,AC,SZ,DT,FP);
sep_line(pf, '─', 12, 8, 5, 9, 45, 0);
for (i=j=0; i<file_total_count; i++) {
if (dm[i]->priv <= lp[P_DUP].priv[x] && /* within priv limit and */
!filename_cmp(dm, i)) { /* (pseudo) equal filenames */
if (oper_mode==VERBOSE && (j%5)==0) {
fprintf(stdout, " %5u\r", j); /* display count by 5 */
fflush(stdout);
}
if (dm[i]->fname[0] != '\0') { /* not a comment-entry */
j++; /* count duplicates */
fprintf(pf,"%-12.12s %8.8s %15s ",
dm[i]->fname,
dm[i]->parea->name,
f_size_date(dm[i]->size, dm[i]->wdate,
dm[i]->cdate, dm[i]->ctime));
desc_part(pf,
(dm[i]->fpath==NULL) ? dm[i]->parea->pname :
dm[i]->fpath,
41, 41, P_DUP);
}
}
}
if (oper_mode==VERBOSE)
fprintf(stdout," %5u\n",j);
signature(pf,today); /* leave fingerprint */
fclose(pf); /* finished with .DUP file */
}
else
fprintf(stderr, MSG_OPO, outfile, 0);
}
/* ---------------------------------------------- */
/* Compare filename */
/* Returns 0 if equal (or to be considered equal) */
/* ---------------------------------------------- */
int filename_cmp(FILECHAIN **dm,
unsigned int k) /* index in dm-array */
{
char f1[9],f2[9]; /* filenames */
int i, rc; /* index, (default) rc */
rc = 1; /* assume not duplicate */
non_wild_init(8, f1, dm[k]->fname); /* filename of current entry */
f1[8] = '\0'; /* end of string */
if (k > 0) { /* not very first */
i = k-1; /* previous entry */
non_wild_init(8, f2, dm[i]->fname); /* entry before */
f2[8] = '\0'; /* end of string */
if (!stricmp(f1,f2)) { /* equal filenames */
rc = 0; /* an equal filename found */
while (i >= 0 && !stricmp(f1,f2)) { /* equal filenames */
if (dup_ext(dm, k, i)) /* (pseudo) unequal */
return(1); /* non-duplicate -> 'unequal' */
if (--i >= 0) { /* within array bound */
non_wild_init(8, f2, dm[i]->fname); /* entry before */
f2[8] = '\0'; /* end of string */
}
} /* no more 'before' duplicates */
} /* maybe any next equal */
}
if (k < file_total_count-1) { /* not very last */
i = k+1; /* next entry */
non_wild_init(8, f2, dm[i]->fname); /* entry before */
f2[8] = '\0'; /* end of string */
if (!stricmp(f1,f2)) { /* next filename equal */
rc = 0; /* an equal found */
while (i<=file_total_count-1 && !stricmp(f1,f2)) { /* search */
if (dup_ext(dm, k, i)) /* (pseudo) unequal */
return(1); /* non-duplicate -> unequal */
if (++i <= file_total_count-1) { /* within array bounds */
non_wild_init(8, f2, dm[i]->fname); /* next entry */
f2[8] = '\0'; /* end of string */
}
} /* no more 'after' duplicates */
} /* no next equal filename */
}
return(rc); /* 1 = not any equal filename */
}
/* ----------------------------------------------------- */
/* Test for files to be considered NOT duplicates: */
/* To be called when filenames are equal if the pair of */
/* extension is specified in the NON_DUP_EXT table. */
/* If the pair is in the table the files will not be */
/* reported as duplicate -> return(1) here. */
/* Otherwise return(0) -> consider as equal files */
/* ----------------------------------------------------- */
int dup_ext(FILECHAIN **dm,
unsigned int k1, /* index of 1st entry */
unsigned int k2) /* index of 2nd entry */
{
char *p1, *p2; /* pointers to ext */
int i; /* counter */
p1 = strrchr(dm[k1]->fname, '.'); /* offset dot in fn 1 */
p2 = strrchr(dm[k2]->fname, '.'); /* offset dot in fn 2 */
if (p1!=NULL && p2!=NULL) { /* both have an extension */
++p1; ++p2; /* 1st char after dots */
if (stricmp(p1, p2)) { /* extensions are not equal */
for (i=0; strlen(non_dup_ext[i])>0; i++,i++) { /* scan table */
if (!stricmp(p1,non_dup_ext[i]) && /* first equal to first */
!stricmp(p2,non_dup_ext[i+1])) /* second to second */
return(1); /* considered unequal*/
else if (!stricmp(p1,non_dup_ext[i+1]) && /* first to second */
!stricmp(p2,non_dup_ext[i])) /* second to first */
return(1); /* considered unequal */
}
}
}
return(0); /* files (pseudo) equal */
}
/* ---------------------------------------------------------------- */
/* Produce the FILES.BBS files for all area's */
/* Sort on name within priv-group, date or as in input FILES.BBS */
/* Call them FILESBBS.xx (where 'xx' is a 2-character area-name). */
/* Put them in the directory indicated by AREA.DAT for 'listfile'. */
/* ---------------------------------------------------------------- */
void make_fil(FILECHAIN **dm,
DOWNPATH _HUGE *area,
unsigned int x)
{
FILE *pf; /* file handle */
char outfile[MAXPATH]; /* file spec new FILES.bbs */
char oldfile[MAXPATH]; /* file spec old FILES.bbs */
char ac[40]; /* area name */
unsigned int i,j,m,fc; /* counters */
int c_priv; /* privilege */
if (oper_mode == VERBOSE)
fprintf(stdout, MSG_SRT, file_total_count, area_total_count,
"FILES.BBS-files");
switch(lp[P_FIL].sortflag) {
case ALPHA: psort(dm,0,file_total_count-1,sort_fil); break;
case TIMESTAMP: psort(dm,0,file_total_count-1,sort_al2); break;
case KEEPSEQ: psort(dm,0,file_total_count-1,sort_akp); break;
default: break;
}
if (oper_mode != QUIET)
fprintf(stdout, MSG_REP, "new FILES.BBS files");
fc = preproc_area(area, dm, lp[P_FIL].priv[x]); /* count files, bytes */
pf = NULL; /* no file open yet */
ac[0] = '\0'; /* init with null-string */
for (i=0; i<file_total_count; i++) {
if (strcmp(ac,dm[i]->parea->name)) { /* new area group */
if (pf != NULL) /* end of previous group */
fclose(pf); /* finished */
strcpy(ac, dm[i]->parea->name); /* new area */
c_priv = dm[i]->parea->priv; /* new AREA-priv */
/* generate new "FILES.BBS" */
if (strlen(filesbbs_path) > 0) { /* FIL:path parameter specified */
strcpy(outfile,filesbbs_path); /* copy path */
if (max_aname <= 3) { /* short areanames */
strcat(outfile,lp[P_FIL].name); /* standard filename */
strcat(outfile,DOT); /* separator */
strncat(outfile, ac, 3); /* extension: 3 chars areaname */
}
else { /* long areanames */
strcat(outfile,ac); /* filename: areaname */
strcat(outfile,DOT); /* separator */
strcat(outfile, lp[P_FIL].ext); /* standard extension */
}
}
else if (strlen(dm[i]->parea->filesbbs) > 0) { /* "ListFile" spec */
strcpy(outfile,dm[i]->parea->filesbbs);
strcpy(oldfile,outfile); /* backup file */
for (j=strlen(oldfile), m=1;
(j-m)>0 && m<5 && outfile[j-m]!='.'; ++m); /* search '.'*/
if (m>=5 || (j-m)<=0) /* no extension found: */
m=0; /* concat to end of name */
strcpy(oldfile+j-m,DOT); /* add separator */
strcat(oldfile,BAK); /* backup file extension */
unlink(oldfile); /* erase old backup file */
rename(outfile,oldfile); /* rename current to backup */
}
else { /* default directory */
strcpy(outfile,dm[i]->parea->pname); /* path to download dir */
strcat(outfile,lp[P_FIL].name); /* add filename */
strcat(outfile,DOT); /* add separator */
strcpy(oldfile,outfile); /* backup file */
strcat(oldfile,BAK); /* backup file extension */
strcat(outfile,lp[P_FIL].ext); /* add BBS-extension */
unlink(oldfile); /* erase old backup file */
rename(outfile,oldfile); /* rename current to backup */
}
if (oper_mode == VERBOSE) /* progress reporting */
fprintf(stdout, MSG_REP, outfile);
else if (oper_mode != QUIET) {
fprintf(stdout, DOT);
fflush(stdout);
}
pf = fopen(outfile,WRITE);
if (pf != NULL) {
if (max_aname <= 3) { /* short areanames */
fprintf(pf,"%s\f\n%s%s ║ %-.*s\n",
FILPREFX, FILPREFX, strnblk(ac,3,FONT3,LINE1),
79-3-strlen(strnblk(ac,3,FONT3,LINE1)),
dm[i]->parea->adesc);
fprintf(pf,"%s%s ║ Available: %u files (%lu.%lu MB)\n",
FILPREFX,strnblk(ac,3,FONT3,LINE2),
dm[i]->parea->file_count, /* area filecount */
(dm[i]->parea->byte_count+52428L)/1048576L, /* 100K*/
((dm[i]->parea->byte_count+52429L)/104857L)%10); /*.1K*/
fprintf(pf,"%s%s ║",
FILPREFX, strnblk(ac,3,FONT3,LINE3));
if (lp[P_FIL].exclflag != EXCLPRIV)
fprintf(pf," Privilege: %-.9s",
priv_name[dm[i]->parea->priv-TWIT]); /* area priv */
fprintf(pf,"\n");
fprintf(pf,"%s%s ║ ",
FILPREFX, strnblk(ac,3,FONT3,LINE4));
if (dm[i]->parea->newest != NULL) { /* newest file */
dm[i]->parea->newest->fname,
fprintf(pf,"Newest: %s dd %8s",
dm[i]->parea->newest->fname,
f_date(dm[i]->parea->newest->wdate));
fprintf(pf," (avail: %8s)",
f_date(dm[i]->parea->newest->cdate));
}
fprintf(pf,"\n");
}
else { /* long areanames */
fprintf(pf,"%s\f\n", FILPREFX);
for (j=0; j<title_lines[lp[P_FIL].tfont]; ++j) /* block name */
fprintf(pf, "%s%s\n", FILPREFX,
strnblk(ac, 8, lp[P_FIL].tfont,j));
fprintf(pf,"%s", FILPREFX); /* start separator line */
sep_line(pf, '─', 78, 0);
fprintf(pf,"%s %-.77s\n", FILPREFX, dm[i]->parea->adesc);
fprintf(pf,"%s Available: %u files (%lu.%lu MB)\n",
FILPREFX, dm[i]->parea->file_count,
(dm[i]->parea->byte_count+52428L)/1048576L, /* 100K*/
((dm[i]->parea->byte_count+52429L)/104857L)%10); /* */
if (lp[P_FIL].exclflag != EXCLPRIV)
fprintf(pf,"%s Privilege: %-.9s\n",
FILPREFX, priv_name[dm[i]->parea->priv-TWIT]);
if (dm[i]->parea->newest != NULL) {
dm[i]->parea->newest->fname,
fprintf(pf,"%s Newest: %s dd %8s",
FILPREFX, dm[i]->parea->newest->fname,
f_date(dm[i]->parea->newest->wdate));
fprintf(pf," (avail: %8s)\n",
f_date(dm[i]->parea->newest->cdate));
}
}
fprintf(pf,"%s", FILPREFX);
sep_line(pf, '─', 78, 0);
file_incl(pf,P_FIL); /* insert user-'logo' */
fprintf(pf,"%s%s %s %s %s\n%s",
FILPREFX, FN, SZ, DT, DS, FILPREFX);
sep_line(pf, '─', 11, 7, 9, 48, 0);
}
else /* failed to open new FILES.BBS */
fprintf(stderr, MSG_OPO, outfile, 3); /* ??? */
} /* endif */
if (pf != NULL) { /* check for open file */
if (dm[i]->priv <= lp[P_FIL].priv[x]) { /* specified reporting lvl*/
if (dm[i]->priv > c_priv) { /* higher priv group within area */
c_priv = dm[i]->priv; /* set new */
fprintf(pf,"%c%c\n", '\20',
(c_priv>SYSOP) ? 'S' : priv_name[c_priv-TWIT][0]);
}
if (dm[i]->fname[0] != '\0') { /* filename present */
if (dm[i]->fpath != NULL) /* explicit pathspec */
fprintf(pf,"%s%s ", dm[i]->fpath, /* path */
dm[i]->fname); /* filename */
else
fprintf(pf,"%-12.12s ", dm[i]->fname); /* filename */
if (lp[P_FIL].longflag==LONGLIST) /* 'long' format req'd */
fprintf(pf," %15s", /* file size + date */
f_size_date(dm[i]->size, dm[i]->wdate,
dm[i]->cdate, dm[i]->ctime));
if (dm[i]->dl_b==1 || dm[i]->dl_t==1) { /* download flags */
fprintf(pf,"/");
if (dm[i]->dl_b==1) /* free bytes flag */
fprintf(pf,"b");
if (dm[i]->dl_t==1) /* free time flag */
fprintf(pf,"t");
}
fprintf(pf," %-s\n", dm[i]->fdesc); /* description as 1 piece */
}
else if(lp[P_FIL].sortflag == KEEPSEQ) /* comment, '/K' spec'd */
fprintf(pf,"%-s\n", dm[i]->fdesc);
}
}
}
if (pf != NULL) /* end of last FILES.BBS */
fclose(pf); /* finished with FILES.bbs file */
} /* end */
/* ------------------------------ */
/* Produce the BinkleyTerm OKFile */
/* (area's in downpath sequence!) */
/* ------------------------------ */
void make_ok(FILECHAIN **dm,
DOWNPATH _HUGE *area,
unsigned int x)
{
FILE *pf; /* file handle */
char outfile[MAXFN]; /* file names */
unsigned int i,j; /* counters */
sprintf(outfile,"%s.%s%c",
lp[P_OK].name,
lp[P_OK].ext,
priv_name[lp[P_OK].priv[x]-TWIT][0]);
pf = fopen(outfile,WRITE); /* output file */
if (pf != NULL) {
if (oper_mode != QUIET)
fprintf(stdout, MSG_REP, outfile);
file_incl(pf, P_OK); /* insert magic filenames */
preproc_area(area, dm, lp[P_OK].priv[x]); /* count files, bytes */
if (lp[P_OK].longflag == LONGLIST) { /* LONG list requested */
for (i=0; i<file_total_count; i++) { /* all files in chain */
if (dm[i]->priv <= lp[P_OK].priv[x] && /* check file privilege */
dm[i]->fname[0] != '\0') /* filename present */
fprintf(pf, "@%s %s%s\n",
dm[i]->fname,
(dm[i]->fpath==NULL) ? dm[i]->parea->pname :
dm[i]->fpath,
dm[i]->fname);
}
}
else {
for (i=j=0; i<area_total_count; i++) /* all area's in array */
if (area[i].priv <= lp[P_OK].priv[x] && /* area privilege */
area[i].file_count > 0) /* and at least 1 file */
if (i<1 || strcmp(area[i].pname,area[j].pname)) { /* not yet in*/
fprintf(pf, "%s*.*\n", area[i].pname);
j = i; /* index of last 'printed' */
}
}
fclose(pf); /* finished with .ALL file */
}
else
fprintf(stderr, MSG_OPO, outfile, 0); /* open failed */
}